

/**
 * 分页函数
 * pno--页数
 * psize--每页显示记录数
 * 分页部分是从真实数据行开始，因而存在加减某个常数，以确定真正的记录数
 * 纯js分页实质是数据行全部加载，通过是否显示属性完成分页功能
 **/
function goPage(pno, psize) {
    var itable = document.getElementById("Stu_table");
    var num = itable.rows.length;//表格所有行数(所有记录数)
    console.log(num);
    var totalPage = 0;//总页数
    var pageSize = psize;//每页显示行数
    //总共分几页
    if (num / pageSize > parseInt(num / pageSize)) {
        totalPage = parseInt(num / pageSize) + 1;
    } else {
        totalPage = parseInt(num / pageSize);
    }
    var currentPage = pno;//当前页数
    var startRow = (currentPage - 1) * pageSize + 1;//开始显示的行 31
    var endRow = currentPage * pageSize;//结束显示的行  40
    endRow = (endRow > num) ? num : endRow;  //40
    console.log(endRow);
    //遍历显示数据实现分页
    for (var i = 1; i < (num + 1); i++) {
        var irow = itable.rows[i - 1];
        if (i >= startRow && i <= endRow) {
            irow.style.display = "table-row";
        } else {
            irow.style.display = "none";
        }
    }
    var tempStr = "共" + num + "条记录 分" + totalPage + "页 当前第" + currentPage + "页";
    if (currentPage > 1) {
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (1) + "," + psize + ")\">首页</a>";
        tempStr += "<a><span class=\"glyphicon glyphicon-chevron-left\" onClick=\"goPage(" + (1) + "," + psize + ")\"></span></a>";
    } else {
        tempStr += "首页";
        tempStr += "<span class=\"glyphicon glyphicon-chevron-left\"></span>";
    }
    if (currentPage < totalPage) {
        tempStr += "<a><span class=\"glyphicon glyphicon-chevron-right\" onClick=\"goPage(" + (currentPage + 1) + "," + psize + ")\"></span></a>";
        tempStr += "<a href=\"#\" onClick=\"goPage(" + (totalPage) + "," + psize + ")\">尾页</a>";
    } else {
        tempStr += "<span class=\"glyphicon glyphicon-chevron-right\"></span>";
        tempStr += "尾页";
    }
    document.getElementById("barcon").innerHTML = tempStr;
}
//刷新按钮
$(".re_text_btn").click(function () {
    window.onload = "http://localhost:8080/J03_T12_P02/getTest?";

});

///设置删除学生
function deleteStu(sid) {
    $.ajax({
        url: "deleteStu",
        type: "POST",
        data: {sid: sid, action: "delete_stu"},
        success: function (data) {
            if (data < 1) {
                alert("删除失败1");
                return;
            }
            $("#tr" + sid).remove();
        },
        error: function () {}
    });
}
//删除题库中的单个题目
function deleteTest(qid) {
    $.ajax({
        url: "deleteStu",
        type: "POST",
        data: {qid: qid, action: "delete_test"},
        success: function (data1) {
            if (data1 < 1) {
               // alert("删除失败2");
            }
            $("#tr" + qid).remove();
        },
        error: function () {}
    });
}
//设置管理员的学生详情页面的动态效果
function diplay_first() {
    $(" .line_first").css("display", "block");
    $(" .line_second").css("display", "none");
    $("#Stu_table_details").css("display", "table");
    $("#Cou_table_details").css("display", "none");
}
function diplay_second() {
    $(" .line_first").css("display", "none");
    $(" .line_second").css("display", "block");
    $("#Stu_table_details").css("display", "none");
    $("#Cou_table_details").css("display", "table");
}
//设置学生详情页面的成绩信息
function showGrade() {

    $(".grade_canvas").fadeIn(500);
    $(".grade_canvas #150_18__gradeGraph").css("left", "150px");
    $(".grade_canvas #150_18__gradeGraph").css("top", "18px");
    $(".grade_canvas #27_35_100_gradeGraph").css("left", "1px");
    $(".grade_canvas #27_35_100_gradeGraph").css("top", "26px");
    $(".grade_canvas #27_81_80_gradeGraph").css("left", "9px");
    $(".grade_canvas #27_81_80_gradeGraph").css("top", "72px");
    $(".grade_canvas #27_127_60_gradeGraph").css("left", "9px");
    $(".grade_canvas #27_127_60_gradeGraph").css("top", "118px");
    $(".grade_canvas #27_173_40_gradeGraph").css("left", "9px");
    $(".grade_canvas #27_173_40_gradeGraph").css("top", "164px");
    $(".grade_canvas #27_219_20_gradeGraph").css("left", "9px");
    $(".grade_canvas #27_219_20_gradeGraph").css("top", "210px");
    $(".grade_canvas #27_265_0_gradeGraph").css("left", "18px");
    $(".grade_canvas #27_265_0_gradeGraph").css("top", "256px");

    //$(".grade_canvas span").css("display","inline");
}
function hideGrade() {
    $(".grade_canvas").fadeOut(300);
}
function all_logout() {
    if (confirm("即将关闭该页面，确认退出登录？")) {
        $.ajax({
            url: "logout",
            type: 'post',
            success: function () {
                window.close();
                window.open("http://localhost:8080/J03_T12_P02/index.html");

            }

        });
    }
}
//添加课程时，课程名失焦事件
function coursenameOnblur() {

    $.ajax({
        url: "getallCourse",
        type: 'GET',
        dataType: 'json',
        data: {coursename: $("#add_form #cid").val(), action1: "getBycourseName"},
        success: function (list) {
            $(".span-iscourse").css("display", "none");
            $.each(list, function (index, arylist) {
                $(".input-courseid").empty();
                $(".input-courseid").append("<option value=\"" + arylist.courseId + "\">" + arylist.courseId + "</option>");
            });
        },
        error: function () {
            $(".span-iscourse").css("display", "inline");
        }
    });
}
//添加课程时，学号失焦事件
function sidOnblur() {

    $.ajax({
        url: "getallStu",
        type: 'GET',
        data: {sid: $("#add_form #sid").val(), action: "isrepeat"},
        success: function (isrepeat) {
            if(isrepeat>0){
                $(".span-sid-ok").css("display", "none");
                $(".span-sid").css("display", "inline");
            }
            else{
                $(".span-sid").css("display", "none");
                $(".span-sid-ok").css("display", "inline");
            }
        },
        error: function () {
           alert("学号不为空");
        }
    });
}
function courseidOnblur(){
    $.ajax({
        url: "operaCourse",
        type: 'POST',
        data: {courseid: $("#add_form #courseid").val(), action: "isrepeatCourse"},
        success: function (isrepeat) {
            if(isrepeat>0){
               $(".span-course-repeat").css("display", "inline");
            }
            else{
                $(".span-course-repeat").css("display", "none");
            }
        },
        error: function () {
           
        }
    });
}
//随机切换个性签名
$(document).ready(function(){
    var title=$(document).attr("title");
    $("#nd-title").html(title);
});
function changeAdminSignature(index){
    var ary=["人不为己，谁愿早起","要适当吃一点，才有力气减肥","人间正道是沧桑，活的不要太嚣张","好好学习，天天向上","开启管理员的一天吧"];
    document.getElementById("admin-signature").innerHTML=ary[index];
}
//批量删除操作
function deleteAllBox(){
    var option=$("input:checkbox:checked");
    var status=true;
    var checkedid="";
    for(var i=0,len=option.length;i<len;i++){
        if(status){
            status=false;
            checkedid+=option[i].value;
        }
        else{
            checkedid+=","+option[i].value;
        }
    }
    var flag=window.confirm("你确定要删除吗");
    if(flag){
        $.ajax({
            url:'admin_deleteBox',
            type:'get',
            data:{qid:checkedid,action:deleteTest},
            success:function(data){
                window.location.reload();
            },
            error:function(){
                alert("不支持删除单个试题");
            }
        });
        
    }
    else{
        return;
    }

}
function repeat(){window.location.reload();}
//全选功能
function checkAll(){
    $("input:checkbox").prop("checked",true);
}
function uncheckAll(){
    $("input:checkbox").prop("checked",false);
}